﻿@inherits ProComponentBase
@page "/resource"
<PageTitle>@T("ResourceFiles")</PageTitle>
<MTabs Value="_selectedProjectIdentity" ValueChanged="HandleProjectIdentityChanged">
    @foreach (var project in _projects)
    {
        <MTab Value="project.Identity" Class="py-3 text-none">
            <span class="px-12 h8 @(_selectedProjectIdentity==project.Identity?"primary--text":"regular2--text")">@project.Name</span>
        </MTab>
    }
</MTabs>
<div class="mt-6" style="position: relative;">
    @if (_resourceData.Any())
    {
        foreach (var app in _resourceData)
        {
            <MCard Flat Class="rounded-4 mb-6">
                <MCardTitle Class="px-6">
                    <div>
                        <span class="emphasis--text h6">@app.Name</span>
                        <SIcon Size="20" Color="emphasis2">keyboard_arrow_right</SIcon>
                    </div>
                    <MSpacer></MSpacer>
                    @if (app.Resources.Any())
                    {
                        <SButton Class="mr-6" Icon Fab OnClick="()=> ShowDialog(ConfirmDialogTypes.DeleteResources, Guid.Empty,app.Identity)" Small Dark>
                            <SIcon Color="error">mdi-delete</SIcon>
                        </SButton>
                    }
                    <SButton Icon Fab OnClick="()=>AddResourceFile(app.Identity)" Small Dark Class="primary" Color="">
                        <SIcon>mdi-plus</SIcon>
                    </SButton>
                </MCardTitle>
                @if (app.Resources.Any())
                {
                    <MCardText Class="pb-6">
                        <MRow>
                            @{
                                var resourcesIndex = 0;
                                var isShowExpandIcon = app.Resources.Count > 4;
                                <div style="width:calc(100% - 44px);" class="d-flex flex-wrap">
                                    @foreach (var item in app.Resources)
                                    {
                                        var colIndex = resourcesIndex++;
                                        <MCol Style="@(colIndex >= 4 && !app.IsExpand ? "display:none" : "")" Cols="12" Md="3">
                                            <MHover>
                                                <div @attributes="context.Attrs" class="@($"full-width fill-hover rounded-2 d-flex justify-center align-center regular--text h5")" style="height:119px">
                                                    @if (context.Hover)
                                                    {
                                                        <SButton Icon Class="align-self-center mr-4" OnClick="()=> ShowDialog(ConfirmDialogTypes.DeleteResourceVersion, item.Id, string.Empty)">
                                                        <SIcon Size="24" Color="error">mdi-delete</SIcon>
                                                        </SButton>
                                                        <span class="d-flex px-15" style="height: 24px;">
                                                            <MDivider Vertical />
                                                        </span>
                                                        <SButton Icon Class="align-self-center mr-4" OnClick="()=>_resourceInfoModal?.OpenModalAsync(item)!">
                                                        <SIcon Size="24" Color="emphasis2" Tooltip="@T("View")">mdi-eye</SIcon>
                                                        </SButton>
                                                    }
                                                    else
                                                    {
                                                        <span>@item.Version</span>
                                                    }
                                                </div>
                                            </MHover>
                                        </MCol>
                                    }
                                </div>
                                @if (isShowExpandIcon)
                                {
                                    <div class="ml-1">
                                        <SButton Icon OnClick="() => app.IsExpand = !app.IsExpand" Style="transform: translate(-12%, 120%);" Class="m-size--small float-right" Color="">
                                        <SIcon>@(app.IsExpand ? "mdi-chevron-up" : "mdi-chevron-down")</SIcon>
                                            </SButton>
                                        </div>
                                }
                            }
                        </MRow>
                    </MCardText>
                }
            </MCard>
        }
    }
    else if (!_showProgressbar)
    {
        <SEmptyPlaceholder Height="calc(100vh - 192px);" />
    }
    <Loading ShowProgressbar="_showProgressbar" Style="height: calc(100vh - 192px)" />
</div>
<SSimpleDialog OkText="@T("SureDelete")" OnOk="OnSureDelete" @bind-Value="_showConfirmDialog" Title="@_confirmTitle" HideCancel OkColor="#FF5252" OkClass="full-width scheduler-confirm-dialog-ok-button">
    <ChildContent>
        <span class="d-flex d-flex flex-column justify-center align-center" style="text-align:center">
            @_confirmMessage
        </span>
    </ChildContent>
</SSimpleDialog>

<AddSchedulerResourceFiles @ref="_addResourceModal" OnAfterSubmit="GetResourceData">
</AddSchedulerResourceFiles>

<SchedulerResourceFilesInformation @ref="_resourceInfoModal"></SchedulerResourceFilesInformation>
